<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>第 20 题</title>
    <script type="text/javascript">
        /*
            20、用户输入一个数字n，计算1+2+3+4+……n的和。
        */
        setTimeout(() => {
            // 让用户输入一个数字
            var oNum = parseInt(prompt("请输入一个正整数", "10"));

            // 设置累加器
            var oCumulative = 0;
            for (var oF = 1; oF <= oNum; oF++) {
                oCumulative = oCumulative + oF;
            }

            // 输出到控制台
            console.log(oCumulative);
        }, 0);
    </script>
</head>

<body>

</body>

</html>